﻿package mortal.game.view.lookPlayerInfo.view
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.gengine.debug.*;
    import com.mui.controls.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.resource.*;
    import mortal.game.resource.configBase.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.best.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.forging.data.*;
    import mortal.game.view.playerSystem.view.*;
    import mortal.game.view.skill.*;

    public class LookPlayerAttributePanel extends GSprite
    {
        private var _attrNameArray:Array;
        private var _attribute:Vector.<String>;
        private var _valArr:Array;
        private var _targetDic:Dictionary;
        private var _slookPlayerInfo:SLookPlayerInfo;
        private var _attackVal:BitmapNumberText;
        private var _physDefenseVal:BitmapNumberText;
        private var _magicDefenseVal:BitmapNumberText;
        private var _penetrationVal:BitmapNumberText;
        private var _joukVal:BitmapNumberText;
        private var _hitVal:BitmapNumberText;
        private var _critVal:BitmapNumberText;
        private var _toughnessVal:BitmapNumberText;
        private var _blockVal:BitmapNumberText;
        private var _expertiseVal:BitmapNumberText;
        private var _comBat:BitmapNumberText;
        private var _shengmingBar:BaseProgressBar;
        private var _mofaBar:BaseProgressBar;
        private var _jinyanBar:BaseProgressBar;
        private var _fightAttribute:SFightAttribute;

        public function LookPlayerAttributePanel()
        {
            this._attrNameArray = [Language.getString(30124), Language.getString(30126), Language.getString(30125), Language.getString(30127), Language.getString(30128), Language.getString(30129), Language.getString(30130), Language.getString(30131), Language.getString(30132), Language.getString(30133)];
            this._attribute = new Vector.<String>;
            this._targetDic = new Dictionary();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:ToolTipSprite = null;
            var _loc_2:GTextFormat = null;
            super.createDisposedChildrenImpl();
            this._attribute.push("attack", "life", "physDefense", "magicDefense", "penetration", "jouk", "hit", "crit", "toughness", "block", "expertise");
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.playerModule_attrBg, 0, 0, this));
            _loc_1 = UICompomentPool.getUICompoment(ToolTipSprite);
            _loc_1.toolTipData = Language.getString(35016);
            this.addChild(_loc_1);
            this.pushUIToDisposeVec(_loc_1);
            _loc_2 = GlobalStyle.textFormatAnHuan;
            _loc_2.size = 12;
            this._comBat = UIFactory.bitmapNumberText(128, 40, "GuildCopyNum.png", 24, 32, -6, this, 9, BitmapNumberText.Mid);
            this._comBat.toolTipData = Language.getString(35015);
            _loc_2 = GlobalStyle.textFormatPutong;
            _loc_2.size = 10;
            this._shengmingBar = UICompomentPool.getUICompoment(BaseProgressBar);
            this._shengmingBar.setBg(ImagesConst.PetLifeBg, true, 150, 12);
            this._shengmingBar.setProgress(ImagesConst.PetLife, true, 1, 1, 148, 10);
            this._shengmingBar.setLabel(BaseProgressBar.ProgressBarTextNumber, 0, -4, 150, 8, _loc_2, "{0}");
            this._shengmingBar.x = 85;
            this._shengmingBar.y = 249;
            this.addChild(this._shengmingBar);
            this._mofaBar = UICompomentPool.getUICompoment(BaseProgressBar);
            this._mofaBar.setBg(ImagesConst.PetLifeBg, true, 150, 12);
            this._mofaBar.setProgress(ImagesConst.PetLifespan, true, 1, 1, 148, 10);
            this._mofaBar.setLabel(BaseProgressBar.ProgressBarTextNumber, 0, -4, 150, 8, _loc_2);
            this._mofaBar.x = 85;
            this._mofaBar.y = 272;
            this.addChild(this._mofaBar);
            this._jinyanBar = UICompomentPool.getUICompoment(BaseProgressBar);
            this._jinyanBar.setBg(ImagesConst.PetLifeBg, true, 150, 12);
            this._jinyanBar.setProgress(ImagesConst.PetExp, true, 1, 1, 148, 10);
            this._jinyanBar.setLabel(BaseProgressBar.ProgressBarTextPercent, 0, -4, 150, 8, _loc_2);
            this._jinyanBar.mouseChildren = false;
            this._jinyanBar.mouseEnabled = true;
            this._jinyanBar.buttonMode = true;
            this._jinyanBar.x = 85;
            this._jinyanBar.y = 295;
            this.addChild(this._jinyanBar);
            this._valArr = [];
            this._attackVal = this.createAttrVal();
            this._valArr.push(this._attackVal);
            this._physDefenseVal = this.createAttrVal();
            this._valArr.push(this._physDefenseVal);
            this._magicDefenseVal = this.createAttrVal();
            this._valArr.push(this._magicDefenseVal);
            this._penetrationVal = this.createAttrVal();
            this._valArr.push(this._penetrationVal);
            this._joukVal = this.createAttrVal();
            this._valArr.push(this._joukVal);
            this._hitVal = this.createAttrVal();
            this._valArr.push(this._hitVal);
            this._critVal = this.createAttrVal();
            this._valArr.push(this._critVal);
            this._toughnessVal = this.createAttrVal();
            this._valArr.push(this._toughnessVal);
            this._blockVal = this.createAttrVal();
            this._valArr.push(this._blockVal);
            this._expertiseVal = this.createAttrVal();
            this._valArr.push(this._expertiseVal);
            _loc_2 = GlobalStyle.textFormatAnHuan;
            _loc_2.size = 12;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_2:BitmapNumberText = null;
            for each (_loc_2 in this._valArr)
            {
                
                _loc_2.dispose(param1);
            }
            this._valArr = [];
            this._shengmingBar.dispose(param1);
            this._mofaBar.dispose(param1);
            this._jinyanBar.dispose(param1);
            this._comBat.dispose(param1);
            this._shengmingBar = null;
            this._mofaBar = null;
            this._jinyanBar = null;
            this._comBat = null;
            this._attackVal = null;
            this._physDefenseVal = null;
            this._magicDefenseVal = null;
            this._penetrationVal = null;
            this._joukVal = null;
            this._hitVal = null;
            this._critVal = null;
            this._toughnessVal = null;
            this._blockVal = null;
            this._expertiseVal = null;
            this._slookPlayerInfo = null;
            this._targetDic = new Dictionary();
            this._attribute.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function createTargetList() : void
        {
            var _loc_1:BaseItem = null;
            var _loc_2:int = 0;
            while (_loc_2 < 4)
            {
                
                _loc_1 = UICompomentPool.getUICompoment(BaseItem);
                _loc_1.setItemStyle(34, null, 2, 2);
                this.addChild(_loc_1);
                _loc_1.x = _loc_2 * 45 + 46;
                _loc_1.y = 162;
                this._targetDic[this.getTypeByIndex(_loc_2)] = _loc_1;
                this.updateTargetByType(this.getTypeByIndex(_loc_2));
                this.pushUIToDisposeVec(_loc_1);
                _loc_2++;
            }
            return;
        }// end function

        private function getTypeByIndex(param1:int) : String
        {
            var _loc_2:String = null;
            switch(param1)
            {
                case 0:
                {
                    _loc_2 = "strengthen";
                    break;
                }
                case 1:
                {
                    _loc_2 = "suitdefense";
                    break;
                }
                case 2:
                {
                    _loc_2 = "medal";
                    break;
                }
                case 3:
                {
                    _loc_2 = "jewel";
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        public function updateTargetByType(param1:String) : void
        {
            var _loc_2:* = undefined;
            switch(param1)
            {
                case "strengthen":
                {
                    _loc_2 = this.getStrengthenTarget();
                    break;
                }
                case "jewel":
                {
                    _loc_2 = this.getForgingGemTarget();
                    break;
                }
                case "suitdefense":
                {
                    _loc_2 = this.getSuitGroupTarget();
                    break;
                }
                case "medal":
                {
                    _loc_2 = this.getMedalTarget();
                    break;
                }
                default:
                {
                    break;
                }
            }
            (this._targetDic[param1] as BaseItem).toolTipData = _loc_2;
            return;
        }// end function

        private function getMedalTarget()
        {
            (this._targetDic["medal"] as BaseItem).source = "TargetMedal.jpg";
            (this._targetDic["medal"] as BaseItem).setQualiy(1, "Target_");
            (this._targetDic["medal"] as BaseItem).setAmountLabel("");
            (this._targetDic["medal"] as BaseItem).bitmap.filters = [FilterConst.colorFilter2];
            return Language.getString(35326);
        }// end function

        private function getAttrValue(param1:TEquipTarget) : String
        {
            var _loc_3:Boolean = false;
            var _loc_4:int = 0;
            var _loc_2:String = "";
            while (_loc_4 < this._attribute.length)
            {
                
                if (param1.hasOwnProperty(this._attribute[_loc_4]) && param1[this._attribute[_loc_4]] > 0)
                {
                    if (!_loc_3)
                    {
                        _loc_2 = _loc_2 + (GameDefConfig.instance.getFightAttributeName(this._attribute[_loc_4]) + ": +" + param1[this._attribute[_loc_4]] + "     ");
                    }
                    else
                    {
                        _loc_2 = _loc_2 + (GameDefConfig.instance.getFightAttributeName(this._attribute[_loc_4]) + ": +" + param1[this._attribute[_loc_4]] + "\n");
                    }
                    _loc_3 = !_loc_3;
                }
                _loc_4++;
            }
            return _loc_2;
        }// end function

        private function getStrengTargetLevel() : int
        {
            var _loc_1:ItemData = null;
            var _loc_3:ItemData = null;
            var _loc_4:SPlayerItem = null;
            var _loc_2:Array = [];
            for each (_loc_4 in this._slookPlayerInfo.playerItems)
            {
                
                _loc_3 = new ItemData(_loc_4);
                if (!EquipmentUtil.isEquipFashion(_loc_3))
                {
                    _loc_2.push(_loc_3);
                }
            }
            _loc_1 = this.getLowestLevelEquip2(_loc_2);
            if (_loc_1 && _loc_1.extInfo.strengthen >= 5)
            {
                return _loc_1.extInfo.strengthen;
            }
            return 0;
        }// end function

        public function getLowestLevelEquip2(param1:Array) : ItemData
        {
            param1.sort(this.sortOnStrengLevel);
            return param1[0] as ItemData;
        }// end function

        private function sortOnStrengLevel(param1:ItemData, param2:ItemData) : int
        {
            if (EquipmentUtil.compareStrengLevel(param1, param2) < 0)
            {
                return -1;
            }
            if (EquipmentUtil.compareStrengLevel(param1, param2) > 0)
            {
                return 1;
            }
            return 0;
        }// end function

        private function getStrengthenTarget() : String
        {
            var _loc_3:String = null;
            var _loc_4:TEquipTarget = null;
            var _loc_5:int = 0;
            var _loc_1:* = PlayerTargetConfig.instance.getTargetListByType("strengthen");
            var _loc_2:* = this.getStrengTargetLevel();
            while (_loc_5 < _loc_1.length)
            {
                
                _loc_4 = _loc_1[_loc_5];
                if (_loc_4.level == _loc_2)
                {
                    break;
                }
                else
                {
                    _loc_4 = null;
                }
                _loc_5++;
            }
            if (_loc_4)
            {
                if (_loc_5 == (_loc_1.length - 1))
                {
                    _loc_3 = "<font color=\'#1ccc31\'>" + Language.getString(30155) + Language.getString(35327) + _loc_4.level + "</font>\n" + this.getAttrValue(_loc_4);
                }
                else
                {
                    _loc_3 = "<font color=\'#1ccc31\'>" + Language.getString(30156) + Language.getString(35327) + _loc_4.level + "</font>\n" + this.getAttrValue(_loc_4);
                }
                (this._targetDic["strengthen"] as BaseItem).source = "TargetStrenge_1.png";
            }
            else
            {
                _loc_3 = Language.getString(35328);
                (this._targetDic["strengthen"] as BaseItem).source = "TargetStrenge_0.png";
            }
            return _loc_3;
        }// end function

        private function getEquipGemCombat() : int
        {
            var _loc_2:int = 0;
            var _loc_3:ItemData = null;
            var _loc_4:SPlayerItem = null;
            var _loc_5:Array = null;
            var _loc_6:EquipRecommendGemData = null;
            var _loc_1:* = this._slookPlayerInfo.playerItems;
            for each (_loc_4 in _loc_1)
            {
                
                _loc_3 = new ItemData(_loc_4);
                _loc_5 = this.getEquipGemData(_loc_3);
                for each (_loc_6 in _loc_5)
                {
                    
                    _loc_2 = _loc_2 + getGemCombat(_loc_6.gemData);
                }
            }
            return _loc_2;
        }// end function

        private function getEquipGemData(param1:ItemData) : Array
        {
            var _loc_5:EquipRecommendGemData = null;
            var _loc_6:TEquipJewelMatch = null;
            var _loc_7:ItemData = null;
            var _loc_2:Array = [];
            var _loc_3:* = param1.extInfo;
            var _loc_4:int = 1;
            while (_loc_4 <= 8)
            {
                
                if (_loc_3["h" + _loc_4] && _loc_3["h" + _loc_4] != "0")
                {
                    _loc_5 = new EquipRecommendGemData();
                    _loc_6 = EquipJewelMatchConfig.instance.getInfoByType(param1.itemInfo.type);
                    _loc_5.equipData = param1;
                    _loc_5.gemHoleIndex = _loc_4;
                    _loc_5.gemItemCode = int(_loc_3["h" + _loc_4].split("#")[0]);
                    _loc_5.gemType = _loc_6.jeweltype;
                    _loc_5.gemName = _loc_6.desc + Language.getString(35329);
                    _loc_7 = new ItemData(int(_loc_3["h" + _loc_4].split("#")[0]));
                    _loc_5.gemData = _loc_7;
                    _loc_5.recommendType = BestConst.RecommendType_GemStreng;
                    _loc_2.push(_loc_5);
                }
                _loc_4++;
            }
            return _loc_2;
        }// end function

        private function getForgingGemTarget() : String
        {
            var _loc_3:String = null;
            var _loc_4:TEquipTarget = null;
            (this._targetDic["jewel"] as BaseItem).setAmountLabel("");
            (this._targetDic["jewel"] as BaseItem).setQualiy(1, "Target_");
            (this._targetDic["jewel"] as BaseItem).source = "TargetGem_0.png";
            return Language.getString(35326);
            if (_loc_4)
            {
                if (_loc_5 == (_loc_2.length - 1))
                {
                    _loc_3 = "<font color=\'#1ccc31\'>" + Language.getString(30155) + Language.getString(35330) + _loc_4.combat + "</font>\n" + this.getAttrValue(_loc_4);
                }
                else
                {
                    _loc_3 = "<font color=\'#1ccc31\'>" + Language.getString(30156) + Language.getString(35331) + _loc_4.combat + "</font>\n" + this.getAttrValue(_loc_4);
                }
                (this._targetDic["jewel"] as BaseItem).source = "TargetGem_1.png";
            }
            else
            {
                _loc_3 = Language.getString(35328);
                (this._targetDic["jewel"] as BaseItem).source = "TargetGem_0.png";
            }
            return _loc_3;
        }// end function

        private function getSuitGroupTarget() : String
        {
            var _loc_2:String = null;
            var _loc_3:TEquipTarget = null;
            var _loc_4:ItemEquipInfo = null;
            var _loc_5:TSuit = null;
            var _loc_6:Boolean = false;
            var _loc_7:Array = null;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_12:int = 0;
            (this._targetDic["suitdefense"] as BaseItem).setAmountLabel("");
            (this._targetDic["suitdefense"] as BaseItem).source = "TargetSuit_0.png";
            (this._targetDic["suitdefense"] as BaseItem).setQualiy(1, "Target_");
            return Language.getString(35326);
            if (_loc_6)
            {
                _loc_4 = PlayerTargetPanel.getSuilItemInfo(_loc_3, _loc_11);
                _loc_5 = ItemConfig.instance.getSuitById(_loc_4.suitId);
                _loc_10 = _loc_5.type.split("#").length;
                _loc_7 = _loc_5.skill.split("#");
                _loc_8 = _loc_7[0];
                _loc_9 = _loc_7[1];
                if (_loc_12 == (_loc_1.length - 1))
                {
                    _loc_2 = "<font color=\'#1ccc31\'>" + Language.getString(30155) + Language.getStringByParam(30158, _loc_10, _loc_4.level, ColorConfig.instance.getItemColor(_loc_4.color).colorText, "", SkillUtil.getSkillDesc(_loc_8) + "\n" + SkillUtil.getSkillDesc(_loc_9));
                }
                else
                {
                    _loc_2 = "<font color=\'#1ccc31\'>" + Language.getString(30156) + Language.getStringByParam(30158, _loc_10, _loc_4.level, ColorConfig.instance.getItemColor(_loc_4.color).colorText, "", SkillUtil.getSkillDesc(_loc_8) + "\n" + SkillUtil.getSkillDesc(_loc_9));
                }
                (this._targetDic["suitdefense"] as BaseItem).source = "TargetSuit_" + (_loc_4.level > 30 ? (50) : (_loc_4.level)) + ".png";
            }
            else
            {
                _loc_2 = Language.getString(35328);
                (this._targetDic["suitdefense"] as BaseItem).source = "TargetSuit_0.png";
            }
            return _loc_2;
        }// end function

        private function createAttrVal() : BitmapNumberText
        {
            var _loc_1:* = this._valArr.length;
            var _loc_2:int = 86;
            var _loc_3:int = 318.5;
            var _loc_4:Number = 23;
            var _loc_5:* = GlobalStyle.textFormatBai;
            _loc_5.size = 12;
            _loc_5.align = TextFormatAlign.LEFT;
            var _loc_6:* = UIFactory.bitmapNumberText(_loc_2, _loc_3 + _loc_4 * _loc_1, "RoleInfoNum.png", 8, 10, -1, this, 14);
            _loc_6.toolTipData = Language.getString(35005 + _loc_1);
            return _loc_6;
        }// end function

        public function updateInfo(param1:SLookPlayerInfo) : void
        {
            this._slookPlayerInfo = param1;
            this._fightAttribute = param1.cellFight;
            this.updateAttr();
            this.updateComBat();
            this.updateLife();
            this.updateMana();
            this.updateExp();
            this.createTargetList();
            return;
        }// end function

        private function updateLife() : void
        {
            this._shengmingBar.setValue(this._slookPlayerInfo.life, this._fightAttribute.maxLife);
            return;
        }// end function

        private function updateMana() : void
        {
            this._mofaBar.setValue(this._slookPlayerInfo.mana, this._fightAttribute.maxMana);
            return;
        }// end function

        private function updateExp() : void
        {
            var _loc_1:* = ConfigCenter.getConfigs(ConfigConst.expLevel, "level", this._slookPlayerInfo.miniPlayer.level, true) as TExperience;
            this._jinyanBar.setValue(this._slookPlayerInfo.experience, _loc_1.upgradeNeedExperience);
            return;
        }// end function

        public function updateLevel() : void
        {
            var _loc_1:* = ConfigCenter.getConfigs(ConfigConst.expLevel, "level", this._slookPlayerInfo.miniPlayer.level, true) as TExperience;
            this._jinyanBar.totalValue = _loc_1.upgradeNeedExperience;
            return;
        }// end function

        private function updateAttr() : void
        {
            Log.debug("战斗属性更新");
            this._attackVal.text = this._fightAttribute.attack.toString();
            this._physDefenseVal.text = this._fightAttribute.physDefense.toString();
            this._magicDefenseVal.text = this._fightAttribute.magicDefense.toString();
            this._penetrationVal.text = this._fightAttribute.penetration.toString();
            this._joukVal.text = this._fightAttribute.jouk.toString();
            this._hitVal.text = this._fightAttribute.hit.toString();
            this._critVal.text = this._fightAttribute.crit.toString();
            this._toughnessVal.text = this._fightAttribute.toughness.toString();
            this._blockVal.text = this._fightAttribute.block.toString();
            this._expertiseVal.text = this._fightAttribute.expertise.toString();
            return;
        }// end function

        private function updateComBat() : void
        {
            this._comBat.text = this._slookPlayerInfo.miniPlayer.combat.toString();
            return;
        }// end function

        public static function getGemCombat(param1:ItemData) : int
        {
            var _loc_2:String = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            if (param1)
            {
                _loc_4 = param1.itemInfo.type;
                _loc_2 = GameDefConfig.instance.getItem("FightRoleAttribute", _loc_4).text;
                _loc_2 = transFightRoleAttr(_loc_2);
                _loc_3 = param1.itemInfo.effect;
                return CombatUtil.getCombatValueByName(_loc_2, _loc_3);
            }
            return 0;
        }// end function

        public static function transFightRoleAttr(param1:String) : String
        {
            switch(param1)
            {
                case "maxLife":
                {
                    param1 = "life";
                    break;
                }
                case "maxMana":
                {
                    param1 = "mana";
                    break;
                }
                case "physicalDefense":
                {
                    param1 = "physDefense";
                    break;
                }
                case "magicalDefense":
                {
                    param1 = "magicDefense";
                    break;
                }
                default:
                {
                    break;
                }
            }
            return param1;
        }// end function

    }
}
